﻿Public Class clsPropertyBuilder
    Property propList As Dictionary(Of String, String)

    Sub New()
        propList = New Dictionary(Of String, String)
    End Sub

    Sub AddID(sID As String)
        AddProperty("ID", sID)
    End Sub

    Sub AddID(sID As String, bNewLine As Boolean)
        AddProperty("ID", sID, True)
    End Sub

    Sub AddAutoPostBack(sValue As Boolean)
        AddProperty("AutoPostBack", sValue.ToString.ToLower)
    End Sub

    Sub AddEnableBackgroundColor(sValue As Boolean)
        AddProperty("EnableBackgroundColor", sValue.ToString.ToLower)
    End Sub

    Sub AddEnableBackgroundColor(sValue As Boolean, bNewLine As Boolean)
        AddProperty("EnableBackgroundColor", sValue.ToString.ToLower, bNewLine)
    End Sub

    Sub AddLabel(sValue As String)
        AddProperty("Label", sValue)
    End Sub

    Sub AddEmptyText(sValue As String)
        AddProperty("EmptyText", sValue)
    End Sub

    Sub AddRequired(sValue As Boolean)
        AddProperty("Required", sValue.ToString.ToLower)
    End Sub

    Sub AddPosition(sValue As String)
        AddProperty("Position", sValue)
    End Sub

    Sub AddHeight(sValue As String)
        AddProperty("Height", sValue & "px")
    End Sub

    Sub AddWidth(sValue As String)
        AddProperty("Width", sValue & "px")
    End Sub

    Sub AddHidden(sValue As Boolean)
        AddProperty("Hidden", sValue.ToString.ToLower)
    End Sub

    Sub AddHidden(sValue As Boolean, bNewLine As Boolean)
        AddProperty("Hidden", sValue.ToString.ToLower, bNewLine)
    End Sub

    Sub AddRunAtServer()
        AddProperty("runat", "server")
    End Sub

    Sub AddRunAtServer(bNewLine As Boolean)
        AddProperty("runat", "server", bNewLine)
    End Sub

    Sub AddShowBorder(sValue As Boolean)
        AddProperty("ShowBorder", sValue.ToString.ToLower)
    End Sub

    Sub AddProperty(propName As String, propValue As String)
        propList.Add(propName, propValue)
    End Sub

    Sub AddTitle(sValue As String)
        AddProperty("Title", sValue)
    End Sub

    Sub AddAutoScroll(sValue As Boolean)
        AddProperty("AutoScroll", sValue.ToString.ToLower)
    End Sub

    Sub AddEnableCollapse(sValue As Boolean)
        AddProperty("EnableCollapse", sValue.ToString.ToLower)
    End Sub

    Sub AddLayout(sValue As String)
        AddProperty("Layout", sValue)
    End Sub

    Sub AddIconURL(sValue As String)
        AddProperty("IconUrl", "~/images/" & sValue & ".gif")
    End Sub

    Sub AddSplit(sValue As Boolean)
        AddProperty("Split", sValue.ToString.ToLower)
    End Sub

    Sub AddEnableSplitTip(sValue As Boolean)
        AddProperty("EnableSplitTip", sValue.ToString.ToLower)
    End Sub

    Sub AddShowHeader(sValue As Boolean)
        AddProperty("ShowHeader", sValue.ToString.ToLower)
    End Sub

    Sub AddRequiredMessage(sValue As String)
        AddProperty("RequiredMessage", sValue)
    End Sub

    Sub AddShowEmptyLabel(sValue As Boolean)
        AddProperty("ShowEmptyLabel", sValue.ToString.ToLower)
    End Sub

    Sub AddShowRedStar(sValue As Boolean)
        AddProperty("ShowRedStar", sValue.ToString.ToLower)
    End Sub

    Sub AddProperty(propName As String, propValue As String, bNewLine As Boolean)
        propList.Add(propName, propValue & vbNewLine)
    End Sub

    Sub DeleteProperty(propname As String)
        If propList.ContainsKey(propname) = True Then propList.Remove(propname)
    End Sub

    Function Render() As String
        Dim sb As New StringBuilder
        For Each kvp As KeyValuePair(Of String, String) In propList
            sb.Append(kvp.Key)
            sb.Append("=")
            sb.Append(Kimmo.clsDL.QuoteString(kvp.Value))
            sb.Append(" ")
        Next
        Dim sRslt As String = sb.ToString
        sRslt = Kimmo.clsDL.RemDelim(sRslt, " ")
        Return sRslt
    End Function
End Class
